package com.ling.luo.base.consumer;


//import com.alibaba.rocketmq.client.consumer.DefaultMQPullConsumer;
//import com.alibaba.rocketmq.client.consumer.MessageQueueListener;
//import com.alibaba.rocketmq.client.exception.MQClientException;
//import com.alibaba.rocketmq.common.message.MessageQueue;

import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.MessageQueueListener;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.common.message.MessageQueue;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 发送异步消息
 *
 * @author luohoujian
 * @since 2021/05/29
 */
public class Consumer {

    public static void main(String[] args) throws MQClientException {
        //1.创建消费者Consumer，制定消费者组名
        //DefaultMQPullConsumer consumer = new DefaultMQPullConsumer("group1");
        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("please_rename_unique_group_name");
        //2.指定Nameserver地址
        consumer.setNamesrvAddr("127.0.0.1:9876");
        //3.订阅主动Topic和Tag
        consumer.subscribe("Jodie_topic_1023", "TagA");
        //4.li
        consumer.registerMessageListener(new MessageListenerConcurrently() {
            @Override
            public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
                System.out.println(new String(msgs.get(0).getBody()));
                return null;
            }
        });
        //5.启动消费者consumer
        consumer.start();

    }
}
